def isMatch(expression):
    # 定义括号匹配关系
    brackets = {
        '(': ')',
        '[': ']',
        '{': '}',
        '<': '>'
    }
    
    # 所有引号
    quotes = {'"', "'", '`'}
    
    stack = []
    in_quote = None  # 记录当前在哪个引号中，如："、'、`
    
    i = 0
    while i < len(expression):
        char = expression[i]

        if in_quote is None:
            # 不在引号中，正常处理括号和引号
            if char in brackets:
                stack.append(brackets[char])  # 压入期望的右括号
            elif char in quotes:
                in_quote = char  # 进入引号
            elif char in brackets.values():
                if not stack or char != stack.pop():
                    return False
        else:
            # 在引号中，只关心对应的结束引号
            if char == in_quote:
                in_quote = None  # 引号结束
            # 其他字符忽略处理
        i += 1

    # 最后栈必须为空，并且不在引号中
    return len(stack) == 0 and in_quote is None

# === DO NOT modify the code below ===
def main():
    s1 = input()
    print(isMatch(s1))
    
if __name__ == '__main__':
    main()
# === DO NOT modify the code above ===